package com.proxy.custom;

import com.proxy.demo.Person;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: shengong
 * @Date: 2019/3/30 10:58
 * @Description:
 */
public class SGMeipo implements SGInvocationHandler {

    private Person target;

    public Object getInstance(Person target){
        this.target = target;
        Class clazz = target.getClass();
        System.out.println("被代理的对象class是"+clazz);
        return SGProxy.newProxyInstance(new SGClassLoader(),clazz.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//        System.out.println("我是媒婆：你的性别是:"+this.target.getSex());
        System.out.println("开始查找...");
//        this.target.findLove();
        method.invoke(this.target,args);
        System.out.println("OK ");
        return null;
    }
}
